home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / ole2book.zip / CHAP07.ZIP / CHAP07 / PATRON / PAGES.H < prev    next >
C/C++ Source or Header  |  1993-06-07  |  12KB  |  375 lines

  1. /*
  2.  * PAGES.H
  3.  * Modifications for Chapter 7
  4.  *
  5.  * Definitions and function prototypes for the Pages window control
  6.  * as well as the CPage and CTenant classes.
  7.  *
  8.  * Copyright (c)1993 Microsoft Corporation, All Rights Reserved
  9.  *
  10.  * Kraig Brockschmidt, Software Design Engineer
  11.  * Microsoft Systems Developer Relations
  12.  *
  13.  * Internet  :  kraigb@microsoft.com
  14.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  15.  */
  16.  
  17.  
  18. #ifndef _PAGES_H_
  19. #define _PAGES_H_
  20.  
  21. //We need this for UICursorLoad and new-style cursors.
  22. #include <bttncur.h>
  23.  
  24.  
  25. //Versioning.
  26. #define VERSIONMAJOR                2
  27. #define VERSIONMINOR                0
  28. #define VERSIONCURRENT              0x00020000
  29.  
  30. //Classname
  31. #define SZCLASSPAGES                "pages"
  32.  
  33. #define HIMETRIC_PER_INCH           2540
  34. #define LOMETRIC_PER_INCH           254
  35. #define LOMETRIC_BORDER             60          //Border around page
  36.  
  37.  
  38. //Window extra bytes and offsets
  39. #define CBPAGESWNDEXTRA             (sizeof(LONG))
  40. #define PAGEWL_STRUCTURE            0
  41.  
  42.  
  43.  
  44. //CHAPTER7MOD
  45.  
  46. /*
  47.  * Tenant class describing an individual piece of data in a page.
  48.  * It knows where it sits, what object is inside of it, and what
  49.  * its idenitifer is such that it can find it's storage within a page.
  50.  */
  51.  
  52. //Patron Objects clipboard format
  53. typedef struct tagPATRONOBJECT
  54.     {
  55.     POINTL      ptl;        //Location of object
  56.     POINTL      ptlPick;    //Pick point from drag-drop operation.
  57.     SIZEL       szl;        //Extents of object (absolute)
  58.     FORMATETC   fe;         //Actual object format.
  59.     } PATRONOBJECT, FAR * LPPATRONOBJECT;
  60.  
  61.  
  62.  
  63. //Values for hit-testing, drawing, and resize-tracking tenants
  64. #define CXYHANDLE       5
  65.  
  66. //Tenant creation types (not persistent)
  67. typedef enum
  68.     {
  69.     TENANTTYPE_NULL=0,
  70.     TENANTTYPE_STATIC,
  71.     } TENANTTYPE, FAR * LPTENANTTYPE;
  72.  
  73.  
  74. //State flags
  75. #define TENANTSTATE_DEFAULT      0x00000000
  76. #define TENANTSTATE_SELECTED     0x00000001
  77.  
  78.  
  79. class __far CTenant
  80.     {
  81.     private:
  82.         HWND            m_hWnd;             //Pages window, same as CPages.
  83.         DWORD           m_dwID;             //Persistent DWORD identifier
  84.         DWORD           m_cOpens;           //Count calls to FOpen.
  85.  
  86.         BOOL            m_fInitialized;     //Something here?
  87.         LPUNKNOWN       m_pObj;             //The object that lives here.
  88.         LPSTORAGE       m_pIStorage;        //Sub-storage for this tenant
  89.  
  90.         FORMATETC       m_fe;               //As used to create the object.
  91.         DWORD           m_dwState;          //State flags
  92.         RECTL           m_rcl;              //Space of this object.
  93.  
  94.         class CPages FAR *m_pPG;            //Pages window
  95.  
  96.     protected:
  97.         HRESULT CreateStatic(LPDATAOBJECT, LPFORMATETC, LPUNKNOWN FAR *);
  98.  
  99.     public:
  100.         CTenant(DWORD, HWND, CPages FAR *);
  101.         ~CTenant(void);
  102.  
  103.         DWORD   GetID(void);
  104.         UINT    GetStorageName(LPSTR);
  105.         UINT    UCreate(TENANTTYPE, LPVOID, LPFORMATETC, LPPOINTL
  106.                     , LPSIZEL, LPSTORAGE, LPPATRONOBJECT, DWORD);
  107.         BOOL    FLoad(LPSTORAGE, LPFORMATETC, LPRECTL);
  108.         BOOL    FOpen(LPSTORAGE);
  109.         void    Close(BOOL);
  110.         BOOL    Update(void);
  111.         void    Destroy(LPSTORAGE);
  112.  
  113.         void    Select(BOOL);
  114.         BOOL    Activate(DWORD);
  115.         void    Draw(HDC, DVTARGETDEVICE FAR *, HDC, int, int, BOOL, BOOL);
  116.         void    Repaint(void);
  117.         void    Invalidate(void);
  118.  
  119.         void    ObjectGet(LPUNKNOWN FAR *);
  120.         void    FormatEtcGet(LPFORMATETC, BOOL);
  121.         void    SizeGet(LPSIZEL, BOOL);
  122.         void    SizeSet(LPSIZEL, BOOL);
  123.         void    RectGet(LPRECTL, BOOL);
  124.         void    RectSet(LPRECTL, BOOL);
  125.     };
  126.  
  127.  
  128. typedef CTenant FAR * LPTENANT;
  129.  
  130. //Return codes for UCreate
  131. #define UCREATE_FAILED              0
  132. #define UCREATE_GRAPHICONLY         1
  133. #define UCREATE_PLACEDOBJECT        2
  134.  
  135.  
  136.  
  137. typedef struct __far tagTENANTLIST
  138.     {
  139.     DWORD       cTenants;
  140.     DWORD       dwIDNext;
  141.     } TENANTLIST, FAR *LPTENANTLIST;
  142.  
  143.  
  144. /*
  145.  * Persistent information we need to save for each tenant, which is done
  146.  * in the tenant list instead of with each tenant.  Since this is a small
  147.  * structure it's best not to blow another stream for it (overhead).
  148.  */
  149. typedef struct tagTENANTINFO
  150.     {
  151.     DWORD       dwID;
  152.     RECTL       rcl;
  153.     FORMATETC   fe;     //Excludes ptd
  154.     } TENANTINFO, FAR *LPTENANTINFO;
  155.  
  156.  
  157. #define SZSTREAMTENANTLIST        "Tenant List"
  158.  
  159. //End CHAPTER7MOD
  160.  
  161.  
  162.  
  163. /*
  164.  * Page class describing an individual page and what things it contains,
  165.  * managing an IStorage for us.
  166.  *
  167.  * A DWORD is used to identify this page as the name of the storage
  168.  * is the string form of this ID.  If we added a page every second,
  169.  * it would take 136 years to overrun this counter, so we can
  170.  * get away with saving it persistently.  I hope this software is
  171.  * obsolete by then.
  172.  */
  173.  
  174. class __far CPage
  175.     {
  176.     private:
  177.         DWORD       m_dwID;             //Persistent DWORD identifier
  178.         LPSTORAGE   m_pIStorage;        //Sub-storage for this page.
  179.         //CHAPTER7MOD
  180.         HWND        m_hWnd;             //Pages window, same as CPages.
  181.         DWORD       m_cOpens;           //Calls to FOpen.
  182.  
  183.         class CPages FAR *m_pPG;        //Pages window
  184.  
  185.         DWORD       m_dwIDNext;
  186.         DWORD       m_cTenants;
  187.         HWND        m_hWndTenantList;   //Listbox that manages our tenant list
  188.  
  189.         UINT        m_iTenantCur;
  190.         LPTENANT    m_pTenantCur;
  191.  
  192.         UINT        m_uHTCode;          //Last hit-test on mouse move.
  193.         UINT        m_uSizingFlags;     //Restrictions on sizing motion.
  194.         BOOL        m_fTracking;        //Tracking resize?
  195.         RECTL       m_rclOrg;           //Original before tracking
  196.         RECTL       m_rcl;              //Tracking rectangle.
  197.         RECTL       m_rclBounds;        //Boundaries for size tracking.
  198.         HDC         m_hDC;              //Tracking hDC.
  199.  
  200.     protected:
  201.         BOOL         FTenantGet(UINT, LPTENANT FAR *, BOOL);
  202.         BOOL         FTenantAdd(UINT, DWORD, LPTENANT FAR *);
  203.         LPDATAOBJECT TransferObjectCreate(LPPOINTL);
  204.  
  205.         //PAGEMOUS.CPP
  206.         UINT         TenantFromPoint(UINT, UINT, LPTENANT FAR *);
  207.         //End CHAPTER7MOD
  208.  
  209.     public:
  210.         //CHAPTER7MOD
  211.         CPage(DWORD, HWND, class CPages FAR *);
  212.         //End CHAPTER7MOD
  213.         ~CPage(void);
  214.  
  215.         DWORD       GetID(void);
  216.         BOOL        FOpen(LPSTORAGE);
  217.         void        Close(BOOL);
  218.         BOOL        Update(void);
  219.         void        Destroy(LPSTORAGE);
  220.  
  221.         //CHAPTER7MOD
  222.         UINT        GetStorageName(LPSTR);
  223.  
  224.         void        Draw(HDC, int, int, BOOL, BOOL);
  225.  
  226.         BOOL        TenantCreate(TENANTTYPE, LPVOID, LPFORMATETC
  227.                         , LPPATRONOBJECT, DWORD);
  228.         BOOL        TenantDestroy(void);
  229.         BOOL        TenantClip(BOOL);
  230.         BOOL        FQueryObjectSelected(HMENU);
  231.  
  232.         //PAGEMOUSE.CPP
  233.         BOOL        OnLeftDown(UINT, UINT, UINT);
  234.         BOOL        OnLeftDoubleClick(UINT, UINT, UINT);
  235.         BOOL        OnLeftUp(UINT, UINT, UINT);
  236.         void        OnNCHitTest(UINT, UINT);
  237.         BOOL        OnSetCursor(UINT);
  238.         void        OnMouseMove(UINT, int, int);
  239.         //End CHAPTER7MOD
  240.     };
  241.  
  242. typedef CPage FAR * LPPAGE;
  243.  
  244.  
  245.  
  246. /*
  247.  * Structures to save with the document describing the device
  248.  * configuration and pages that we have.  This is followed by
  249.  * a list of DWORD IDs for the individual pages.
  250.  */
  251.  
  252. typedef struct __far tagDEVICECONFIG
  253.     {
  254.     DEVMODE     dm;
  255.     char        szDriver[CCHDEVICENAME];
  256.     char        szDevice[CCHDEVICENAME];
  257.     char        szPort[CCHDEVICENAME];
  258.     } DEVICECONFIG, FAR * LPDEVICECONFIG;
  259.  
  260.  
  261. typedef struct __far tagPAGELIST
  262.     {
  263.     DWORD       cPages;
  264.     DWORD       iPageCur;
  265.     DWORD       dwIDNext;
  266.     } PAGELIST, FAR *LPPAGELIST;
  267.  
  268.  
  269. //PAGEWIN.CPP
  270. LRESULT __export FAR PASCAL PagesWndProc(HWND, UINT, WPARAM, LPARAM);
  271. BOOL    __export FAR PASCAL AbortProc(HDC, int);
  272. BOOL    __export FAR PASCAL PrintDlgProc(HWND, UINT, WPARAM, LPARAM);
  273. //CHAPTER7MOD
  274. void                        RectConvertMappings(LPRECT, HDC, BOOL);
  275. //End CHAPTER7MOD
  276.  
  277.  
  278. class __far CPages : public CWindow
  279.     {
  280.     friend LRESULT __export FAR PASCAL PagesWndProc(HWND, UINT, WPARAM, LPARAM);
  281.     friend BOOL    __export FAR PASCAL PrintDlgProc(HWND, UINT, WPARAM, LPARAM);
  282.  
  283.     friend class CPage;
  284.     friend class CTenant;
  285.  
  286.     protected:
  287.         //CHAPTER7MOD
  288.         LPPAGE      m_pPageCur;             //Current page we're viewing
  289.         //End CHAPTER7MOD
  290.         UINT        m_iPageCur;
  291.         UINT        m_cPages;               //Number of pages
  292.  
  293.         HWND        m_hWndPageList;         //Listbox that manages our page list
  294.         HFONT       m_hFont;                //Page font.
  295.         BOOL        m_fSystemFont;          //Is m_hFont system object?
  296.  
  297.         UINT        m_cx;                   //Usable page size in LOMETRIC
  298.         UINT        m_cy;
  299.  
  300.         UINT        m_xMarginLeft;          //Unusable page margins, LOMETRIC
  301.         UINT        m_xMarginRight;
  302.         UINT        m_yMarginTop;
  303.         UINT        m_yMarginBottom;
  304.  
  305.         UINT        m_xPos;                 //Current viewport scroll position.
  306.         UINT        m_yPos;                 //both in *PIXELS*
  307.  
  308.         DWORD       m_dwIDNext;             //Next ID for a page.
  309.         LPSTORAGE   m_pIStorage;            //Root storage of document.
  310.  
  311.         //CHAPTER7MOD
  312.         UINT        m_cf;                   //Application clipboard format.
  313.         BOOL        m_fDirty;
  314.         //End CHAPTER7MOD
  315.  
  316.     protected:
  317.         void      Draw(HDC, BOOL, BOOL);
  318.         void      UpdateScrollRanges(void);
  319.         BOOL      ConfigureForDevice(void);
  320.         BOOL      FPageGet(UINT, LPPAGE FAR *, BOOL);
  321.         BOOL      FPageAdd(UINT, DWORD, BOOL);
  322.  
  323.         //CHAPTER7MOD
  324.         //RectConvertMappings made global.
  325.         void      CalcBoundingRect(LPRECT, BOOL);
  326.         //End CHAPTER7MOD
  327.  
  328.     public:
  329.         //CHAPTER7MOD
  330.         CPages(HINSTANCE, UINT);
  331.         //End CHAPTER7MOD
  332.         ~CPages(void);
  333.  
  334.         BOOL      FInit(HWND, LPRECT, DWORD, UINT, LPVOID);
  335.  
  336.         BOOL      FIStorageSet(LPSTORAGE, BOOL, BOOL); //Was ::New previously
  337.         BOOL      FIStorageUpdate(BOOL);
  338.  
  339.         BOOL      Print(HDC, LPSTR, DWORD, UINT, UINT, UINT);
  340.  
  341.         void      RectGet(LPRECT);
  342.         void      RectSet(LPRECT, BOOL);
  343.         void      SizeGet(LPRECT);
  344.         void      SizeSet(LPRECT, BOOL);
  345.  
  346.         UINT      PageInsert(UINT);
  347.         UINT      PageDelete(UINT);
  348.         UINT      CurPageGet(void);
  349.         UINT      CurPageSet(UINT);
  350.         UINT      NumPagesGet(void);
  351.  
  352.         BOOL      DevModeSet(HGLOBAL, HGLOBAL);
  353.         HGLOBAL   DevModeGet(void);
  354.  
  355.         //CHAPTER7MOD
  356.         BOOL      FIsDirty(void);
  357.         BOOL      DevReadConfig(LPDEVICECONFIG, HDC FAR *);
  358.         BOOL      TenantCreate(TENANTTYPE, LPVOID, LPFORMATETC
  359.                     , LPPATRONOBJECT, DWORD);
  360.         BOOL      TenantDestroy(void);
  361.         BOOL      TenantClip(BOOL);
  362.         BOOL      FQueryObjectSelected(HMENU);
  363.         //End CHAPTER7MOD
  364.     };
  365.  
  366. typedef CPages FAR * LPCPages;
  367.  
  368.  
  369. //Fixed names of streams in the Pages IStorage
  370. #define SZSTREAMPAGELIST        "Page List"
  371. #define SZSTREAMDEVICECONFIG    "Device Configuration"
  372.  
  373.  
  374. #endif  //_PAGES_H_
  375.